package cn.dglydrpy.study.algorithm.od;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author Yyy
 * @date 2024/11/13 20:31
 * @description
 * 1 2 3 4 5 6 7 8 9 10
 * 1
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()){
            String[] inputs = scanner.nextLine().split(" ");
            int[] arr = new int[inputs.length];
            for(int i=0;i<arr.length;i++){
                arr[i] = Integer.valueOf(inputs[i]);
            }
            int ans = myAnswer(arr);
            System.out.println(ans);
        }
    }

    private static int myAnswer(int[] arr) {

        int sum = 0;
        for(int i=0;i<arr.length;i++){
            sum += arr[i];
        }
        int avg = sum / 2;
        
        int tmp = avg + 1;
        int cz = Integer.MAX_VALUE;
        while(tmp > 0){
            
            // 找到和为tmp的组
            ArrayList<Integer> curList = new ArrayList<>();
            
            int curSum = 0;
            for(int i=0;i<curList.size();i++){
                curSum += curList.get(i);
                if(curSum >= tmp){
                    break;
                }
            }
            if(curSum == tmp){
                cz = Math.min(Math.abs(cz),Math.abs(tmp - (sum -tmp)));
            }
            
            tmp--;
        }
        
        return cz;
        
    }
    
    // 能不能在list中找到count个数，让他们的和为sum
    private boolean find(ArrayList<Integer> list,int count,int sum){
        if(count == 0 || list.size() == 0){
            return sum == 0;
        }
        return false;
    }

}
